package flc.ast.adapter;

import android.media.MediaPlayer;
import android.view.View;
import android.widget.SeekBar;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyAudioBean;
import flc.ast.bean.VoiceBean;
import flc.ast.utils.AudioPlayerImpl;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class VoiceAdapter extends StkProviderMultiAdapter<VoiceBean> {

    public VoiceAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(40));
        addItemProvider(new VoiceProvider());
    }

    private class VoiceProvider extends BaseItemProvider<VoiceBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_voice;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, VoiceBean bean) {
            baseViewHolder.setImageResource(R.id.ivVoiceItemImg, bean.getImg());
            AudioPlayerImpl audioPlayer = bean.getAudioPlayer();
            SeekBar seekBar = baseViewHolder.getView(R.id.sbVoice);
            seekBar.setProgress((int) (bean.getVolume() * 100));
            seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    float volume = progress / 100f;
                    bean.setVolume(volume);
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {

                }
            });
        }
    }

}
